package com.windfone.web.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.windfone.common.Constant;
import com.windfone.common.PageUtil;
import com.windfone.model.Software;
import com.windfone.service.SoftwareService;

public class DownloadAction extends ActionSupport {
	private SoftwareService softwareService;
	private int beginRecord;
	private int currentPage;
	private int nextPage;
	private int totalPage;
	private int prevPage;
	private Software bean;
	private int softwareId;
	private int softwareTypeId;
	private List<Software> softwareList;
 
	public String detail() throws Exception {
		bean = softwareService.getSoftwareById(softwareId).get(0);
		return SUCCESS;
	}
	public String execute() throws Exception {
		String whereCondition = "";
		if ( softwareTypeId !=-1 ){
			whereCondition = " AND s.softwareTypeId="+ softwareTypeId;
		}
		PageUtil pu = new PageUtil();
		pu.setCurrentPage(currentPage);
		int totalRecords = softwareService.getAllRecorderNumber(whereCondition) ;
		pu.setTotalRecords( totalRecords );
		pu.setPageSize(Constant.PAGE_SIZE);
		pu.dealPage();
		currentPage = pu.getCurrentPage();
		nextPage = pu.getNextPage();
		totalPage = pu.getTotalPage();
		prevPage = pu.getPrevPage();
		
		beginRecord = Constant.PAGE_SIZE * (currentPage -1);
		if ( beginRecord< 0 )
			beginRecord = 0; 
		softwareList = softwareService.getAllSoftware(beginRecord,whereCondition);		
		return SUCCESS;
	}
	public SoftwareService getSoftwareService() {
		return softwareService;
	}
	public int getBeginRecord() {
		return beginRecord;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public int getNextPage() {
		return nextPage;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public int getPrevPage() {
		return prevPage;
	}
	public Software getBean() {
		return bean;
	}
	public int getSoftwareId() {
		return softwareId;
	}
	public int getSoftwareTypeId() {
		return softwareTypeId;
	}
	public List<Software> getSoftwareList() {
		return softwareList;
	}
 
	public void setSoftwareService(SoftwareService softwareService) {
		this.softwareService = softwareService;
	}
	public void setBeginRecord(int beginRecord) {
		this.beginRecord = beginRecord;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}
	public void setBean(Software bean) {
		this.bean = bean;
	}
	public void setSoftwareId(int softwareId) {
		this.softwareId = softwareId;
	}
	public void setSoftwareTypeId(int softwareTypeId) {
		this.softwareTypeId = softwareTypeId;
	}
	public void setSoftwareList(List<Software> softwareList) {
		this.softwareList = softwareList;
	}
}
